const { Tab } = require('../../assets/libs/zanui/index');

var app = getApp();
Page(Object.assign({}, Tab, {
  data: {
		isHidden: true,
		cdnUrl: '',
		population: 0, // 服务态度评分点数初始值
		distribution: 0,// 准时率评分点数初始值
	
	
    bannerList: [],
    archivesList: [],
    loading: false,
    nodata: false,
    nomore: false,
    tab: {
      list: [],
      selectedId: '0',
      scroll: true,
      height: 44
    },
		/* 自定义导航栏参数 */
		loading: false,
		color: '#FFFFFF',
		background: '#02B3BA',
		show: true,
		animated: false,
		back: true,
		title: "订单详情",
		
		orderDetail: {},
		/* 评价信息 */
		evaluateContent: ''//评价文字内容
  },
  channel: 0,
  page: 1,
	callphone (e){
		wx.makePhoneCall({
			phoneNumber: e.currentTarget.dataset.mobile
		})
	},
  onLoad: function (e) {
		var id = e.id;
		// var id = 1;
    var that = this;
		that.setData({
			cdnUrl: app.cdnUrl,
		});
    that.orderDetail(id);
  },
	/* 订单评价 */
	evaluate: function(){
		var that = this;
		var subData = {
			punctually: that.data.distribution,//准时率评分点数
			serviceAttitude: that.data.population,//服务态度评分点数
			evaluateContent: that.data.evaluateContent,
			id: that.data.orderDetail.id
		}
		app.request('/addons/cms/wxapp.recovery/orderEvaluate', subData, function (data, ret) {
		  app.success(ret.msg);
			that.setData({
				isHidden: true//隐藏模态框
			})
			that.orderDetail(that.data.orderDetail.id);
		}, function (data, ret) {
		  app.error(ret.msg);
		});
	},
	evaluateContentChange:function (e){
		var that = this;
		var value = e.detail.value;
		that.setData({
			evaluateContent: value
		})
	},
	/* 获取订单详情 */
	orderDetail: function (id){
		var that = this;
		app.request('/addons/cms/wxapp.recovery/orderDetail', {
			id: id
		}, function (data, ret) {
		  that.setData({
				orderDetail: data
		  });
		}, function (data, ret) {
		  app.error(ret.msg);
			setTimeout(function(){
				wx.navigateBack({});
			},3000)
		});
	},
  onPullDownRefresh: function () {},
  onReachBottom: function () {},
  onShareAppMessage: function () {
    return {
      title: '蓝之鲸回收',
      desc: '',
      path: '/page/index/index'
    }
  },
  /* 弹窗 */
  showMd: function(e) {
      var that = this;
      // var id = e.currentTarget.dataset.id - 1;
      that.setData({
          isHidden: false,//显示模态框，
      })
  },
  hiddenMd: function() {
      this.setData({
          isHidden: true//隐藏模态框
      })
  },
	//点击准时率评价
	bindDistribution: function (event) {
		var that = this;
		var distribution = that.data.distribution;
		let datatype = event.currentTarget.dataset.type;
		let index = event.currentTarget.dataset.index;
		index = index + 1
		if (datatype == 1) {
			distribution = index;
		} else if (datatype == 2) {
			distribution = distribution + index
		}
		that.setData({
			distribution: distribution
		})
	},
	//点击服务态度评价
	bindPopulation: function (event) {
		var that = this;
		var population = that.data.population;
		let datatype = event.currentTarget.dataset.type;
		let index = event.currentTarget.dataset.index;
		index = index + 1
		if (datatype == 1) {
			population = index;
		} else if (datatype == 2) {
			population = population + index
		}
		that.setData({
			population: population
		})
	},
  
}))
